<head>
<script>

    /* logging */
    var messages = [];
    var log = function (message) {
        messages.push(message);
    };
    window.onload = function () {
        log = function (message) {
            var p = document.createElement('p');
            p.innerHTML = message;
            document.body.appendChild(p);
        };
        for (var i = 0; i < messages.length; i++) {
            log(messages[i]);
        }
    };

    var globalEval = function (text) {
        var head = document.getElementsByTagName("head")[0] || document.documentElement;
        var script = document.createElement('script');
        script.appendChild(document.createTextNode(text));
        head.appendChild(script);
    }

    log('1');
    globalEval("log('2')");
    log('3');

</script>
</head>
